﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MyHotel.MyHotel_MHBaoCaoDoanhThu_BUS_Webservice;
using MyHotel.Reports;


namespace MyHotel
{
    

    public partial class frmBaoCaoDoanhThu : DevComponents.DotNetBar.Office2007Form
    {
        List<Thang> listThang;
        List<ChiTietDoanhThuReport> listDoanhThu;
        public frmBaoCaoDoanhThu()
        {
            InitializeComponent();
        }

        private void cboThang_SelectedValueChanged(object sender, EventArgs e)
        {
            ChiTietDoanhThu[] dsct;
            MHBaoCaoDoanhThuBUSWSSoapClient ws = new MHBaoCaoDoanhThuBUSWSSoapClient();
            if (cboThang.SelectedItem != null)
            {
                int giatri = Convert.ToInt32(cboThang.SelectedValue.ToString());
                if (giatri > 0)
                    dsct = ws.getListDoanhThuThang(giatri);
                else
                    dsct = ws.getListDoanhThuNam();

                listDoanhThu = createListReport(dsct);
                dgvDoanhThu.DataSource = listDoanhThu;
            }
        }

        private List<ChiTietDoanhThuReport> createListReport(ChiTietDoanhThu[] dsct)
        {
            List<ChiTietDoanhThuReport> list = new List<ChiTietDoanhThuReport>();
            foreach (ChiTietDoanhThu ct in dsct)
            {
                ChiTietDoanhThuReport ctReport = new ChiTietDoanhThuReport();
                ctReport.Doanhthu = ct.Doanhthu;
                ctReport.Tenloaiphong = ct.Tenloaiphong;
                ctReport.Tile = ct.Tile;

                list.Add(ctReport);
            }

            return list;
        } 
        private void frmBaoCaoDoanhThu_Load(object sender, EventArgs e)
        {
            listThang = new List<Thang>();
            for (int i = 0; i < 12; ++i)
            {
                Thang t = new Thang();
                t.Tenthang = "Tháng " + Convert.ToString(i + 1);
                t.Giatri = i + 1;
                listThang.Add(t);
            }
            listThang.Add(new Thang { Tenthang = "Cả năm", Giatri = 0 });
            cboThang.DisplayMember = "TenThang";
            cboThang.ValueMember = "GiaTri";
            cboThang.DataSource = listThang;
            cboThang.SelectedIndex = DateTime.Today.Month - 1;
        }

        private void dgvDoanhThu_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            if (e.RowIndex != 1)
            {
                for (int i = 0; i < dgvDoanhThu.Rows.Count; ++i)
                {
                    dgvDoanhThu.Rows[i].Cells[0].Value = i + 1;
                }
            }
        } 
        private void btn_In_Click(object sender, EventArgs e)
        {
            int thang = Convert.ToInt32(cboThang.SelectedValue.ToString());
            frmReviewBaoCaoDoanhThu viewer = new frmReviewBaoCaoDoanhThu(thang, listDoanhThu);
            viewer.ShowDialog();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Bạn có muốn thoát không?", "Thoát", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            if (dr == DialogResult.Yes)
            {
                this.Close();
            }
        } 
    }

    public class ChiTietDoanhThuReport
    {
        private string tenloaiphong;
        public string Tenloaiphong
        {
            get { return tenloaiphong; }
            set { tenloaiphong = value; }
        }
        private int doanhthu;
        public int Doanhthu
        {
            get { return doanhthu; }
            set { doanhthu = value; }
        }
        private double tile;
        public double Tile
        {
            get { return tile; }
            set { tile = value; }
        }
    }

    class Thang
    {
        string tenthang;

        public string Tenthang
        {
            get { return tenthang; }
            set { tenthang = value; }
        }
        int giatri;

        public int Giatri
        {
            get { return giatri; }
            set { giatri = value; }
        }
    }
}